﻿#ifndef _LOGSAVE__ 
#define _LOGSAVE__
#include "stdafx_logm.h"
#include "LOGMlib_EXPORT.h"
/**
* \file LogSave.h
* \brief LogSave.h is header file of class LogSave
*/

namespace LOGM
{
	/** \namespace LOGM
	*	\brief LOGM include all the class and member for log management
	*	 
	*
	*/
	/**
	* \class LogSave
	*this class was designed for save the log from qt4.
	*/
	 class LOGMlib_EXPORT LogSave:public QObject
	{
		 Q_OBJECT

	public:

		explicit LogSave();
		static LogSave *_instance;
		static LogSave *instance();
		
		~LogSave();

signals:
		/**
		* 
		*this singal was designed for broadcast the log changed singal
		*/
		void LogChanged(QtMsgType log_type, const QString &);

	public slots:

		/**
		* 
		*the call back function for dealing with each message from Qt qDebug class
		*/
		friend void logMessageHandler(QtMsgType log_type, const char *msg);
	
		/**
		* 
		*Open or create dir for log file
		*/
		void openLogDir();

		/**
		* 
		*Open log file
		*/
		void openLogFile();

		/**
		* 
		*Close log file 
		*/
		void closeLogFile();

		/**
		* 
		*register call back function
		*/
		void installMessageHandler();

		/**
		* 
		*Format the log with time and send the signal
		*/
		void logText(QtMsgType log_type, const QString &);

	public:
	    static QTextStream *log_Out;	//输出一行日志

	private:
		QDir log_Dir;	/**< var for current working dir*/
		QFile *log_File;/**< var for current log file*/
		
		static QString *log_line_message;
		
		
		QDate logFIleCreatedDate; /**< current date*/
		QTime logFIleCreatedTime; /**< current time*/
		QDateTime logFIleCreatedDateTime;


		friend class ViewLog;
	};
}

#endif